<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:include href="../admin.xsl" />
	<xsl:include href="path.xsl" />
	
	<!-- Запускаем рендер страницы -->
	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
		</head>
		<body>
			<xsl:call-template name="admin-header" />
			
			<div id="blocks">
				<div id="blocks_inner" />
			</div>
			
			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>
			
			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response">
		<div id="path">
			<xsl:apply-templates select="document(concat('xmodule://cp/getPath/', @dir-id))/data/response" mode="cp-path" />
		</div>
		
		<div id="list_cp_items">
			<xsl:apply-templates select="object[@type='cp_item']" />
		</div>
	</xsl:template>
	
	<xsl:template match="object[@type='cp_item']">
		<xsl:param name="useDrag" />
		<xsl:param name="draggedElementPrefix" />
		
		<xsl:param name="dirId" select="property[@name='link_dir_id']/value" />
		<xsl:param name="itemModule" select="property[@name='link_module']/value" />
		<xsl:param name="itemMethod" select="property[@name='link_method']/value" />
		<xsl:param name="icon" select="property[@name='icon']/value" />
		
		<div class="item" id="drag_wrapper_{@id}">
			<span class="drag" id="drag_{@id}">
				<div title="Добавить в избранное" class="icon" onmousedown="dragItemToFavorite('drag_{@id}', {@id})">
					<xsl:attribute name="style">
						<xsl:text>background-image: url("</xsl:text>
						<xsl:choose>
							<xsl:when test="$icon != ''">
								<xsl:value-of select="concat($baseURI, $icon)" />
							</xsl:when>
							<xsl:when test="$itemModule != ''">
								<xsl:value-of select="concat($baseURI, '/images/cp/file.png')" />
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="concat($baseURI, '/images/cp/folder.png')" />
							</xsl:otherwise>
						</xsl:choose>
						<xsl:text>");</xsl:text>
					</xsl:attribute>
				</div>
				
				<div class="link">
					<a>
						<xsl:attribute name="href">
							<xsl:choose>
								<xsl:when test="$itemModule != ''">
									<xsl:value-of select="concat($baseURI, '/admin/', $itemModule)" />
									
									<xsl:if test="$itemMethod != ''">
										<xsl:value-of select="concat('/', $itemMethod)" />
									</xsl:if>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="concat($baseURI, '/admin/cp/dir/', @id)" />
								</xsl:otherwise>						
							</xsl:choose>
						</xsl:attribute>
						<xsl:value-of select="property[@name='title']/value" />
					</a>
				</div>
			</span>
		</div>	
	</xsl:template>
	
</xsl:stylesheet>